
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 07/02/2011 23:40:24
-- Generated from EDMX file: C:\Users\sha\Desktop\DropBox\summer\AidBrella\AidBrella\Models\AidBrellaModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [AidBrella_Alpha];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------


-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'ProjectSet'
CREATE TABLE [dbo].[ProjectSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Description] nvarchar(max)  NULL,
    [StartDate] datetime  NULL,
    [EndDate] datetime  NULL,
    [ProjectSectorId] int  NULL,
    [TotalBudget] nvarchar(max)  NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'UserSet'
CREATE TABLE [dbo].[UserSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [FirstName] nvarchar(max)  NOT NULL,
    [LastName] nvarchar(max)  NOT NULL,
    [UserName] nvarchar(max)  NOT NULL,
    [Created] datetime  NOT NULL,
    [Modified] datetime  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Timestamp] varbinary(max)  NOT NULL,
    [ImageUrl] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'FullAddressSet'
CREATE TABLE [dbo].[FullAddressSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Phone] nvarchar(max)  NOT NULL,
    [Country] nvarchar(max)  NOT NULL,
    [City] nvarchar(max)  NOT NULL,
    [PostCode] nvarchar(max)  NOT NULL,
    [Street] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [WebSite] nvarchar(max)  NOT NULL,
    [ProjectSet_Id] int  NOT NULL
);
GO

-- Creating table 'ProjectSiteSet'
CREATE TABLE [dbo].[ProjectSiteSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ProjectId] int  NOT NULL,
    [Latitude] float  NOT NULL,
    [Longitude] float  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [Timestamp] varbinary(max)  NOT NULL,
    [ProjectSet_Id] int  NOT NULL
);
GO

-- Creating table 'ProjectSectorSet'
CREATE TABLE [dbo].[ProjectSectorSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Timestamp] varbinary(max)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'ProjectSet'
ALTER TABLE [dbo].[ProjectSet]
ADD CONSTRAINT [PK_ProjectSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UserSet'
ALTER TABLE [dbo].[UserSet]
ADD CONSTRAINT [PK_UserSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'FullAddressSet'
ALTER TABLE [dbo].[FullAddressSet]
ADD CONSTRAINT [PK_FullAddressSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectSiteSet'
ALTER TABLE [dbo].[ProjectSiteSet]
ADD CONSTRAINT [PK_ProjectSiteSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectSectorSet'
ALTER TABLE [dbo].[ProjectSectorSet]
ADD CONSTRAINT [PK_ProjectSectorSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [ProjectSet_Id] in table 'FullAddressSet'
ALTER TABLE [dbo].[FullAddressSet]
ADD CONSTRAINT [FK_ProjectSetFullAddress]
    FOREIGN KEY ([ProjectSet_Id])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectSetFullAddress'
CREATE INDEX [IX_FK_ProjectSetFullAddress]
ON [dbo].[FullAddressSet]
    ([ProjectSet_Id]);
GO

-- Creating foreign key on [ProjectSet_Id] in table 'ProjectSiteSet'
ALTER TABLE [dbo].[ProjectSiteSet]
ADD CONSTRAINT [FK_ProjectSetProjectSiteSet]
    FOREIGN KEY ([ProjectSet_Id])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectSetProjectSiteSet'
CREATE INDEX [IX_FK_ProjectSetProjectSiteSet]
ON [dbo].[ProjectSiteSet]
    ([ProjectSet_Id]);
GO

-- Creating foreign key on [ProjectSectorId] in table 'ProjectSet'
ALTER TABLE [dbo].[ProjectSet]
ADD CONSTRAINT [FK_ProjectSectorSetProjectSet]
    FOREIGN KEY ([ProjectSectorId])
    REFERENCES [dbo].[ProjectSectorSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectSectorSetProjectSet'
CREATE INDEX [IX_FK_ProjectSectorSetProjectSet]
ON [dbo].[ProjectSet]
    ([ProjectSectorId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------